# -*- coding: utf-8 -*-
from scrapy.crawler import CrawlerRunner
from scrapy.utils.project import get_project_settings
from jiage315.spiders.medicine import MedicineSpider

from twisted.internet import reactor
from scrapy.utils.log import configure_logging
from scrapy.crawler import CrawlerProcess


def run():
    configure_logging({'LOG_FORMAT': '%(levelname)s: %(message)s'})
    settings = get_project_settings()
    runner = CrawlerRunner(settings)
    # 西药
    runner.crawl(MedicineSpider, start_url='https://www.315jiage.cn/mc118.aspx')
    # 中药
    runner.crawl(MedicineSpider, start_url='https://www.315jiage.cn/mc119.aspx')

    d = runner.join()
    d.addBoth(lambda _: reactor.stop())
    reactor.run()

def run2():
    configure_logging({'LOG_FORMAT': '%(levelname)s: %(message)s'})
    settings = get_project_settings()
    process = CrawlerProcess(settings)
    process.crawl(MedicineSpider, start_url='https://www.315jiage.cn/mc119.aspx')
    process.start()


if __name__ == '__main__':
    run()
